package com.frxuexi.sign

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.SignBeanItem
import com.frxuexi.sign.databinding.ItemSignBinding

class SignAdapter:BaseQuickAdapter<SignBeanItem,BaseViewHolder>(R.layout.item_sign) {

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemSignBinding>(viewHolder.itemView)
    }
    @SuppressLint("ResourceType")
    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        val binding = DataBindingUtil.getBinding<ItemSignBinding>(helper.itemView)!!
        binding.bean=item

        val morning = item.morningCheckIn.split(" ")
        val date = morning[0].replaceFirst("-", "年").replaceFirst("-", "月").plus("日")
        binding.signDate.setText(date)


        val after = if(item.afternoonCheckIn.isNotEmpty()) item.afternoonCheckIn.split(" ")[1] else ""
        binding.signTime.setText("上班：${morning[1]} - 下班：${after}")

        binding.signStatusStart.apply {
            when(item.status){
                "正常"->{
                    setTextColor(context.getColor(com.frxuexi.lib_base.R.color.green))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                }
                "迟到"->{
                    setTextColor(context.getColor(com.frxuexi.lib_base.R.color.darkorange))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                }
                else->{
                    setTextColor(context.getColor(com.frxuexi.lib_base.R.color.redfont))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                }

            }
        }
    }
}